home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / GBlanker / GSource / handlers.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  5KB  |  218 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include "includes.h"
  10. #include "libraries.h"
  11. #include "protos/protos.h"
  12. #include <exec/execbase.h>
  13.  
  14. LONG BlankingDisabled = FALSE;
  15.  
  16. ULONG UsagePercent( VOID )
  17. {
  18.     ULONG OldIdle, OldDisp, Idle, Disp;
  19.     
  20.     OldIdle = (( struct ExecBase * )SysBase )->IdleCount;
  21.     OldDisp = (( struct ExecBase * )SysBase )->DispCount;
  22.     
  23.     Delay( 10 );
  24.     
  25.     Idle = (( struct ExecBase * )SysBase )->IdleCount - OldIdle;
  26.     Disp = (( struct ExecBase * )SysBase )->DispCount - OldDisp;
  27.     
  28.     return Disp * 100 / ( Idle + Disp );
  29. }
  30.  
  31. LONG HandleServerMsg( VOID )
  32. {
  33.     ULONG PubScreenModes;
  34.     BlankMsg *CurMsg;
  35.     
  36.     while( CurMsg = ( BlankMsg * )GetMsg( ServerPort ))
  37.     {
  38.         LONG Type = CurMsg->bm_Type;
  39.         LONG Flags = CurMsg->bm_Flags;
  40.  
  41.         if( Flags & BF_REPLY )
  42.         {
  43.             if(!( Flags & BF_INTERNAL ))
  44.                 FreeVec( CurMsg );
  45.         }
  46.         else
  47.         {
  48.             CurMsg->bm_Flags |= BF_REPLY;
  49.             ReplyMsg(( struct Message * )CurMsg );
  50.         }
  51.         
  52.         switch( Type )
  53.         {
  54.         case BM_DOBLANK:
  55.             if( Flags & BF_REPLY )
  56.             {
  57.                 if( !CheckIO(( struct IORequest * )TimeOutIO ))
  58.                 {
  59.                     AbortIO(( struct IORequest * )TimeOutIO );
  60.                     WaitIO(( struct IORequest * )TimeOutIO );
  61.                     SetSignal( 0L, SIG_TIMER );
  62.                 }
  63.                 if( ServerScr )
  64.                 {
  65.                     UnblankMousePointer( Wnd );
  66.                     CloseScreen( ServerScr );
  67.                     ServerScr = 0L;
  68.                 }
  69.                 if( !PingTask )
  70.                     PingTask = CreateTask( "GarshnePing", -5, PingFunc, 4096 );
  71.                 Blanking = TRUE;
  72.             }
  73.             break;
  74.         case BM_DOTESTBLANK:
  75.             if( Flags & BF_REPLY )
  76.             {
  77.                 if( !PingTask )
  78.                     PingTask = CreateTask( "GarshnePing", -5, PingFunc, 4096 );
  79.                 Blanking = TRUE;
  80.             }
  81.             break;
  82.         case BM_INITMSG:
  83.             if( BlankAfterInit )
  84.             {
  85.                 BlankAfterInit = FALSE;
  86.                 MessageModule( "GarshneClient", BM_DOBLANK );
  87.             }
  88.             break;
  89.         case BM_FAILED:
  90.             if( PingTask )
  91.             {
  92.                 Signal( PingTask, SIGBREAKF_CTRL_C );
  93.                 PingTask = 0L;
  94.             }
  95.             InternalBlank();
  96.             break;
  97.         case BM_SENDBLANK:
  98.             if(( Flags & BF_REPLY )|| BlankingDisabled )
  99.                 break;
  100.             if( ServerScr &&( UsagePercent() > 40 ))
  101.                 break;
  102.             PubScreenModes = SetPubScreenModes( 0L );
  103.             if( Stricmp( Prefs->bp_Blanker, "Random" ))
  104.             {
  105.                 if( !Blanking || ServerScr )
  106.                     MessageModule( "GarshneClient", BM_DOBLANK );
  107.             }
  108.             else
  109.             {
  110.                 if( !Blanking || Prefs->bp_Flags & BF_REPLACE )
  111.                 {
  112.                     MessageModule( "GarshneClient", BM_DELAYEDQUIT );
  113.                     BlankAfterInit = TRUE;
  114.                     LoadModule( Prefs->bp_Dir, Prefs->bp_Blanker );
  115.                 }
  116.                 else if( ServerScr )
  117.                     MessageModule( "GarshneClient", BM_DOBLANK );
  118.             }
  119.             SetPubScreenModes( PubScreenModes );
  120.             break;
  121.         case BM_SENDTEST:
  122.             if(( Flags & BF_REPLY )|| BlankingDisabled )
  123.                 break;
  124.             PubScreenModes = SetPubScreenModes( 0L );
  125.             MessageModule( "GarshneClient", BM_DOTESTBLANK );
  126.             SetPubScreenModes( PubScreenModes );
  127.             break;
  128.         case BM_SENDUNBLANK:
  129.             if( Flags & BF_REPLY )
  130.                 break;
  131.             if( ServerScr )
  132.             {
  133.                 UnblankMousePointer( Wnd );
  134.                 CloseScreen( ServerScr );
  135.                 ServerScr = 0L;
  136.             }
  137.             Blanking = FALSE;
  138.             MessageModule( "GarshneClient", BM_UNBLANK );
  139.             if( PingTask )
  140.             {
  141.                 Signal( PingTask, SIGBREAKF_CTRL_C );
  142.                 PingTask = 0L;
  143.             }
  144.             break;
  145.         default:
  146.             break;
  147.         }
  148.     }
  149.  
  150.     return OK;
  151. }
  152.  
  153. LONG HandleMouseCheck( VOID )
  154. {
  155.     LONG MouseX, MouseY, Lock, Width, Height;
  156.  
  157.     BlankingDisabled = FALSE;
  158.  
  159.     Lock = LockIBase( 0L );
  160.  
  161.     MouseX = IntuitionBase->MouseX;
  162.     MouseY = IntuitionBase->MouseY;
  163.     if( IntuitionBase->FirstScreen )
  164.     {
  165.         Width = IntuitionBase->FirstScreen->Width - 1;
  166.         Height = IntuitionBase->FirstScreen->Height - 1;
  167.     }
  168.     else
  169.     {
  170.         Width = ~0L;
  171.         Height = ~0L;
  172.     }
  173.     
  174.     UnlockIBase( Lock );
  175.  
  176.     switch( Prefs->bp_BlankCorner )
  177.     {
  178.     case BC_UPPERLEFT:
  179.         if( !MouseX && !MouseY )
  180.             timeCount = Prefs->bp_Timeout - 5;
  181.         break;
  182.     case BC_UPPERRIGHT:
  183.         if( !MouseY && MouseX == Width )
  184.             timeCount = Prefs->bp_Timeout - 5;
  185.         break;
  186.     case BC_LOWERRIGHT:    
  187.         if( MouseX == Width && MouseY == Height )
  188.             timeCount = Prefs->bp_Timeout - 5;
  189.            break;
  190.     case BC_LOWERLEFT:
  191.         if( !MouseX && MouseY == Height )
  192.             timeCount = Prefs->bp_Timeout - 5;
  193.         break;
  194.     }
  195.  
  196.     switch( Prefs->bp_DontCorner )
  197.     {
  198.     case BC_UPPERLEFT:
  199.         if( !MouseX && !MouseY )
  200.             BlankingDisabled = TRUE;
  201.         break;
  202.     case BC_UPPERRIGHT:
  203.         if( !MouseY && MouseX == Width )
  204.             BlankingDisabled = TRUE;
  205.         break;
  206.     case BC_LOWERRIGHT:    
  207.         if( MouseX == Width && MouseY == Height )
  208.             BlankingDisabled = TRUE;
  209.            break;
  210.     case BC_LOWERLEFT:
  211.         if( !MouseX && MouseY == Height )
  212.             BlankingDisabled = TRUE;
  213.         break;
  214.     }
  215.  
  216.     return OK;
  217. }
  218.